%%%----------------------------------------------------------------------
%%% File    : cus_ejabberd_c2s.erl
%%% Author  : chen.kangmin
%%%----------------------------------------------------------------------

-module(cus_router).
-author('chen.kangmin').


-export([
    router/3
        ]
       ).


-include("logger.hrl").
-include("ejabberd.hrl").
-include("cus_pb.hrl").
-include("cus.hrl").

router(undefined, ToId, Packet) ->
    case element(1, Packet) of
        messageack ->
            skip;
        pushcontent ->
            skip;
        _ ->
            Cid = element(2, Packet),
            case element(3, Packet) of
                skip ->
                    skip;
                Alert ->
                    spawn(fun() -> cus_push:push_message(ToId, Cid, Alert) end)
            end
    end;
router(Pid, _ToId, Packet) ->
    FixPacket = case element(1, Packet) of
                    messageack ->
                        Packet;
                    pushcontent ->
                        Packet;
                    _ ->
                        element(1, Packet)
                end,
    Pid ! {router, FixPacket}.